﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace C4F.DevKit.WebServicesDemo
{
    public partial class DiggControl : UserControl
    {
        public DiggControl()
        {
            InitializeComponent();
        }

        private void DiggGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewSelectedCellCollection Cells = DiggGrid.SelectedCells;
            if (Cells[0] is System.Windows.Forms.DataGridViewLinkCell)
            {
                DataGridViewLinkCell LinkCell = (DataGridViewLinkCell)Cells[0];
                DemoBrowser BrowserForm = new DemoBrowser((string)LinkCell.Value);
                BrowserForm.Show();
            }
        }

        private void GoButton_Click(object sender, EventArgs e)
        {
            try
            {
                DiggResults = DiggService.GetHeadlines_DS();
                DiggGrid.DataSource = DiggResults;
            }
            catch (System.Net.WebException ex)
            {
                StreamReader streamReader = new StreamReader(ex.Response.GetResponseStream());
                string responseData = streamReader.ReadToEnd();
                streamReader.Close();
                MessageBox.Show(responseData);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
